<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('业务附件表列表')"/>
</head>
<body class="pear-container">

<!--<div class="layui-card">-->
<!--    <div class="layui-card-body">-->
<!--        <form class="layui-form" action="">-->
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label">名称</label>-->
<!--                <div class="layui-input-inline">-->
<!--                    <input type="text" name="searchText" placeholder="" class="layui-input">-->
<!--                </div>-->
<!--                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit-->
<!--                        lay-filter="templateList-query">-->
<!--                    <i class="layui-icon layui-icon-search"></i>-->
<!--                    查询-->
<!--                </button>-->
<!--                <button type="reset" class="pear-btn pear-btn-md">-->
<!--                    <i class="layui-icon layui-icon-refresh"></i>-->
<!--                    重置-->
<!--                </button>-->
<!--            </div>-->
<!--        </form>-->
<!--    </div>-->
<!--</div>-->
<div class="layui-card">
    <div class="layui-card-body">
        <table id="templateList-table" lay-filter="templateList-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="templateList-toolbar">
    <button class="pear-btn pear-btn-warming pear-btn-md"
            lay-event="batchdownload">
        <i class="layui-icon layui-icon-download-circle"></i>
        批量下载
    </button>
</script>

<script type="text/html" id="templatedownload-bar">
        <button class="pear-btn pear-btn-primary pear-btn-sm"
                lay-event="downloadSingle" title="下载单个文件">下载<i class="layui-icon layui-icon-download-circle"></i>
        </button>
</script>

<script type="text/html" id="templateList-bar">

</script>


<script type="text/html" id="templateList-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include :: footer"/>
<script th:inline="javascript" type="text/javascript">
    layui.use(['table', 'form', 'jquery'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;

        var recordId = [[${recordId}]];
        // var fkSubject = [[${fkSubject}]];

        var MODULE_PATH = rootPath + "/InfoFileController/";
        var cols = [
            [
                {type: 'checkbox'},

                {title: '文件名称', field: 'fileName', align: 'center'},

                {title: '后缀名', field: 'suffix', align: 'center'},

                {title: '创建日期', field: 'createDate', align: 'center'},

                {title: '操作', toolbar: '#templatedownload-bar', align: 'center'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#templateList-table',
            url: MODULE_PATH + 'templateList/'+recordId,
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#templateList-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }]
        });

        //table工具栏绑定
        table.on('toolbar(templateList-table)', function (obj) {
            if (obj.event === 'batchdownload') {
                window.batchdownload(obj);
            } else if (obj.event === 'refresh') {
                window.refresh();
            }
        });

        //table工具栏绑定
        table.on('tool(templateList-table)', function (obj) {
            if (obj.event === 'downloadSingle') {
                window.downloadSingle(obj);
            }
        });

        //批量删除
        window.batchdownload = function (obj) {
            var data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            var url = MODULE_PATH + "batchdownload/" + ids;
            var timestamp = Date.parse(new Date());
            downloadFile(url, "模板文件"+timestamp+".zip");

        }

        //单个文件下载
        window.downloadSingle = function (obj) {
            console.log(obj);
            filedata = obj.data
            console.log(filedata);
            id = filedata.id
            fileName = filedata.fileName
            console.log(fileName);
            var url = MODULE_PATH + "downloadsingle/" + id;
            var timestamp = Date.parse(new Date());
            downloadFile(url, fileName);
        }

        //刷新按钮
        window.refresh = function () {
            table.reload('templateList-table');
        }
    })
</script>
</html>